package com.example.venue_reservation_service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.venue_reservation_service.dto.PageDTO;
import com.example.venue_reservation_service.mapper.VenueLogMapper;
import com.example.venue_reservation_service.service.VenueLogService;
import com.example.venue_reservation_service.domain.VenueLog;
import com.example.venue_reservation_service.vo.QueryVO;
import com.example.venue_reservation_service.vo.Result;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
* @author 31586
* @description 针对表【venue_log(系统操作日志表)】的数据库操作Service实现
* @createDate 2025-03-19 16:15:18
*/
@Service
public class VenueLogServiceImpl extends ServiceImpl<VenueLogMapper, VenueLog>
    implements VenueLogService {

    @Override
    @Async
    public void saveLog(VenueLog log) {
        save(log);
    }

    @Override
    public Result queryLogs(PageDTO dto, String key) {
        Page<VenueLog> page = new Page<>(dto.getCurrent(), dto.getSize());
        LambdaQueryWrapper<VenueLog> wrapper = Wrappers.lambdaQuery();
        wrapper.orderByDesc(VenueLog::getCreateTime);
        if (StringUtils.isNotBlank(key)) {
            wrapper.eq(VenueLog::getOperationType, key);
        }
        page = page(page, wrapper);
        QueryVO<VenueLog> vo = new QueryVO<>();
        vo.setTotal(page.getTotal());
        vo.setList(page.getRecords());
        return Result.ok(vo).message("查询成功");
    }
}




